package zuoye;

public class FizzBuzz {
	private int num;
	private int i=1;

	public int getNum() {
		return num;
	}

	public void setNum(int num) {
		this.num = num;
	}

	public FizzBuzz(int num) {
		super();
		this.num = num;
	}

	public void fizz() {
		while(i<=num){
			synchronized (FizzBuzz.class) {
				if(i%3==0 && i%5!=0){
					System.out.println("fizz");
					i++;
				}else{
					try {
						FizzBuzz.class.wait();
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
				FizzBuzz.class.notifyAll();
			}
		}
	}

	public void buzz() {
		while(i<=num){
			synchronized (FizzBuzz.class) {
				if(i%3!=0 && i%5==0){
					System.out.println("buzz");
					i++;
				}else{
					try {
						FizzBuzz.class.wait();
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
				FizzBuzz.class.notifyAll();
			}
		}
	}

	public void fizzbuzz() {
		while(i<=num){
			synchronized (FizzBuzz.class) {
				if(i%3==0 && i%5==0){
					System.out.println("fizzbuzz");
					i++;
				}else{
					try {
						FizzBuzz.class.wait();
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
				FizzBuzz.class.notifyAll();
			}
		}
	}

	public void number() {
		while(i<=num){
			synchronized (FizzBuzz.class) {
				if(i%3!=0 && i%5!=0){
					System.out.println(i);
					i++;
				}else{
					try {
						FizzBuzz.class.wait();
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
				FizzBuzz.class.notifyAll();
			}
		}
	}
}
